import os
import cv2

directory = './data/SM/train4/'

# 只枚举文件
# for category in range(0,9):
fileList = []  

def handle_file(fn):
    img = cv2.imread(fn)
    # print(img.shape[0], img.shape[1])
    if img.shape[0] != 28 or img.shape[1] != 28:
        resized_img = cv2.resize(img, (28, 28))
        print(fn)
        cv2.imwrite(fn, resized_img)
        

def handle_dir(dir):
    for filename2 in os.listdir(dir):
        file_path2 = os.path.join(dir, filename2)
        if os.path.isfile(file_path2):
            handle_file(file_path2)
    
for filename in os.listdir(directory):
    file_path = os.path.join(directory, filename)
    if os.path.isfile(file_path):
        handle_file(file_path)
    elif "other" not in filename:
        handle_dir(file_path)

# for fn in fileList:
#     img = cv2.imread(directory + fn)
#     resized_img = cv2.resize(img, (60, 60))
#     cv2.imwrite(directory + fn, resized_img)
